/*
* Copyright (C) Microsoft. All rights reserved.  
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not 
* use this file except in compliance with the License.  You may obtain a copy 
* of the License at http://www.apache.org/licenses/LICENSE-2.0  
* 
* THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
* WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
* MERCHANTABLITY OR NON-INFRINGEMENT. 
*
* See the Apache License, Version 2.0 for specific language governing 
* permissions and limitations under the License.
*
*/
#pragma once

#include <baja/common.hpp>
#include <baja/graphics.hpp>
#include <journal/common/projection.hpp>

namespace journal { 

namespace b = baja;
namespace a = baja::app;
namespace g = baja::graphics;

struct scene_state
{
    scene_state()
    {
        // NOTE: the coordinate system and the world matrix are both fixed!
        // set up coordinate system by flipping y and z so z is "up"
        coordinateSystemMatrix.set(m::vector3d(1, 0, 0), m::vector3d(0, 0, 1), m::vector3d(0, 1, 0));
        worldMatrix.makeIdentity();
    }

    void apply(const std::shared_ptr<g::iengine>& graphics)
    {
        graphics->setCoordinateSystemMatrix(coordinateSystemMatrix);
        graphics->pushWorldMatrix(worldMatrix, false);

        graphics->replaceCurrentCameraMatrix(camera->matrix());	
        graphics->setAmbientLight(ambient);
        graphics->setLight(0, light);
        graphics->setLightEnable(0, g::enabled_state::enabled);

        projection->apply(graphics);
    }

    m::matrix44 coordinateSystemMatrix;
    m::matrix44 worldMatrix;
    g::light light;
    g::color ambient;
    std::shared_ptr<a::icamera> camera;
    std::shared_ptr<iprojection> projection;
};

} // namespace journal